package com.cloud.autoconfigure;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.cloud.common.filter.XssFilter;
import com.cloud.common.utils.SpringContextHolder;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Configuration
public class AutoConfiguration {

	 @Bean
	    public FilterRegistrationBean xxsFilter() {
	        FilterRegistrationBean bean = new FilterRegistrationBean(new XssFilter());
	        log.info("bean [{}]",bean);
	        return bean;
	    }

	    /**
	     * 分页插件
	     */
	    @Bean
	    public PaginationInterceptor paginationInterceptor() {
	        return new PaginationInterceptor();
	    }

	    /**
	     * 默认加密配置
	     *
	     * @return
	     */
//	    @Bean
//	    @ConditionalOnMissingBean(BCryptPasswordEncoder.class)
//	    public BCryptPasswordEncoder bCryptPasswordEncoder() {
//	        BCryptPasswordEncoder encoder =  new BCryptPasswordEncoder();
//	        log.info("bean [{}]",encoder);
//	        return encoder;
//	    }


	    /**
	     * Spring上下文工具配置
	     *
	     * @return
	     */
	    @Bean
	    @ConditionalOnMissingBean(SpringContextHolder.class)
	    public SpringContextHolder springContextHolder() {
	        SpringContextHolder holder = new SpringContextHolder();
	        log.info("bean [{}]",holder);
	        return holder;
	    }
}
